//
//  ViewController.m
//  tableviewaboutLOL
//
//  Created by 小白 on 16/3/3.
//  Copyright © 2016年 小白. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) NSArray *arr;
@property (nonatomic,weak) UITableView *tableView;
@end

@implementation ViewController
//-(NSArray *)arrLOL
//{
//    if (_arrLOL == nil) {
//        NSString *path = [[NSBundle mainBundle]pathForResource:@"heroes" ofType:@"plist"];
//        NSArray *arr = [NSArray arrayWithContentsOfFile:path];
//        NSMutableArray *mArr = [NSMutableArray array];
//        for (NSDictionary *element  in arr)
//        {
////            lolData *data = [lolData lolDataWithDictionary:element];
//            [mArr addObject:data];
//        }
//        _arrLOL = mArr;
//    }
//    return _arrLOL;
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    //创建tableview
    NSString *path = [[NSBundle mainBundle]pathForResource:@"heroes" ofType:@"plist"];
    self.arr = [NSArray arrayWithContentsOfFile:path];
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 22, 320, 530)];
    [self.view addSubview:tableView];
    self.tableView = tableView;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
  
    

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arr.count;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //查找被移除的单元格
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
   if (cell == nil)
   {
       //没有重复利用的则新建
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
   }
    
    cell.textLabel.text = self.arr[indexPath.row][@"name"];
    cell.imageView.image = [UIImage imageNamed:self.arr[indexPath.row][@"icon"]];
    cell.detailTextLabel.text = self.arr[indexPath.row][@"intro"];
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
